package com.hdoit.kylin.web.common;

import java.util.List;

import com.hdoit.kylin.selfcommon.enums.RoleMapper;
import com.tennetcn.common.enums.ManageContainer;
import com.tennetcn.common.logical.superbase.model.Role;
import com.tennetcn.common.message.LoginModel;


/** 
 * @author      chenghuan
 * @email       79763939@qq.com
 * @createtime  2017年5月17日 上午9:52:33
 * @comment 
 */
public class CommonWebUtils {
	@SuppressWarnings("unchecked")
	public static boolean isStudent(LoginModel loginModel){
		List<Role> roles=(List<Role>)loginModel.getArgument(ManageContainer.SESSION_ARUMENT_ROLES);
		if(roles==null||roles.size()<=0){
			return false;
		}
		return roles.stream().filter(role->RoleMapper.student.equals(role.getRoleMark())).count()>0;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isPostGraduate(LoginModel loginModel){
		List<Role> roles=(List<Role>)loginModel.getArgument(ManageContainer.SESSION_ARUMENT_ROLES);
		if(roles==null||roles.size()<=0){
			return false;
		}
		return roles.stream().filter(role->RoleMapper.postgraduate.equals(role.getMarkCode())).count()>0;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isDoctor(LoginModel loginModel){
		List<Role> roles=(List<Role>)loginModel.getArgument(ManageContainer.SESSION_ARUMENT_ROLES);
		if(roles==null||roles.size()<=0){
			return false;
		}
		return roles.stream().filter(role->RoleMapper.doctor.equals(role.getMarkCode())).count()>0;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isTeacher(LoginModel loginModel){
		List<Role> roles=(List<Role>)loginModel.getArgument(ManageContainer.SESSION_ARUMENT_ROLES);
		if(roles==null||roles.size()<=0){
			return false;
		}
		return roles.stream().filter(role->RoleMapper.teacher.equals(role.getRoleMark())).count()>0;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isManager(LoginModel loginModel){
		List<Role> roles=(List<Role>)loginModel.getArgument(ManageContainer.SESSION_ARUMENT_ROLES);
		if(roles==null||roles.size()<=0){
			return false;
		}
		return roles.stream().filter(role->RoleMapper.manager.equals(role.getRoleMark())).count()>0;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isOperation(LoginModel loginModel){
		List<Role> roles=(List<Role>)loginModel.getArgument(ManageContainer.SESSION_ARUMENT_ROLES);
		if(roles==null||roles.size()<=0){
			return false;
		}
		return roles.stream().filter(role->RoleMapper.operation.equals(role.getRoleMark())).count()>0;
	}
	
}
